import scrapy
import json


class HttpmethodSpider(scrapy.Spider):
    name = "httpmethod"

    def start_requests(self):
        # url = "http://httpbin.org/get?name=qiku"
        # yield scrapy.Request(url, method="get")

        # 如果没有formdata 默认是get
        # yield scrapy.FormRequest(url)

        # 如果使用formdata 默认是post  实测会忽略？后参数
        # yield scrapy.FormRequest(url, method="GET", formdata={"age": "10"})




        url = "http://httpbin.org/post"
        # yield scrapy.Request(url, method="POST", body=json.dumps({"name": "qiku"}))

        yield scrapy.FormRequest(url, formdata={"name": "qiku"}, headers={
            # "content-type": "application/json"

            # 默认( 不用写)
            "content-type": "application/x-www-form-urlencoded"
        })


    def parse(self, response):
        print(response.request.method)
        print(response.request.headers)
